/**
 * @author        Nicolas Bottarini <nicolasbottarini@gmail.com>, 404 <http://www.proyecto404.com>
 * @version       $Rev: 3 $
 * @lastrevision  $Date: 2011-09-12 16:45:37 +0000 (Mon, 12 Sep 2011) $	 
 */
package com.proyecto404.core
{
	import com.proyecto404.core.EventArgs;
	
	import org.osflash.signals.ISignal;
	import org.osflash.signals.Signal;

	public class GenericJob extends BaseObject implements IJob {
		private var _jobBody:Function;
		private var _progress:Signal;
		private var _error:Signal;
		
		public function GenericJob(jobBody:Function) {
			_jobBody = jobBody;
			_progress = new Signal(EventArgs);
			_error = new Signal(EventArgs);
		}
		
		public function execute(callback:Function):void {
			// TODO: Agregar manejo de errores. Try/Catch?
			_jobBody.call(null, callback);
			_progress.dispatch(new EventArgs());
		}
		
		public function get progress():ISignal {
			return _progress;
		}
		
		public function get error():ISignal {
			return _error;
		}
	}
}